TypeScript 定義型別物件


Posted by mijouhsieh on 2024-01-02

官方文件在定義物件型別時,用分號 隔開

var employee : { 
    id: number; 
    name: string; 
}; 

employee = { 
  id: 100, 
  name : "John"
}

之後學到 interface 介面 ,和物件整合

有一些關於要使用分號還是逗號
Should TS interface have a comma or semicolon?

In TypeScript, interfaces and type literals can have members separated by a comma or a semicolon.

It's a good idea to have a consistent style.

They're both valid, but TypeScript prefers semicolon.


#semicolon #TypeScript #object #comma #TS prefer semicolon #interfaces







Related Posts

JS註冊組|函式、方法與物件|JavaScript&jQuery網站互動設計程式進化之道

JS註冊組|函式、方法與物件|JavaScript&jQuery網站互動設計程式進化之道

[ CSS 02 ] 各種裝飾

[ CSS 02 ] 各種裝飾

AppWorks School Batch #16 Front-End Class 學習筆記&心得(駐點階段四:個人專案~Sprint 5)

AppWorks School Batch #16 Front-End Class 學習筆記&心得(駐點階段四:個人專案~Sprint 5)


Comments